//
//  FavoriteManagerViewController.m
//  CityFire
//
//  Created by Liuyz on 2017/8/2.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "FavoriteManagerViewController.h"
#import "MessageViewModel.h"
#import "NSUserDefaults+Tools.h"

@interface FavoriteManagerViewController ()

@property (nonatomic, strong) MessageViewModel *msgViewModel;

@end

@implementation FavoriteManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = kFavovite_TITLE;
    
    [self bindRAC];
    
    self.daysLabel.text = [NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_FAVRITORDAYS];
    [self.stepSliderView setIndex:[[NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_FAVRITORDAYS] intValue]-1];
}

- (void)bindRAC {
    [RACObserve(self.msgViewModel, messageModel) subscribeNext:^(MessageModel *messageModel) {
        if (messageModel) {
            self.daysLabel.text = [messageModel.days stringValue];
        }
    }];
}

- (IBAction)changeValue:(StepSlider *)sender
{
    self.daysLabel.text = [NSString stringWithFormat:@"%ld", sender.index+1];
}

- (IBAction)okBtnClicked:(id)sender
{
    [self.msgViewModel setFavoriteDays:@{@"days" : self.daysLabel.text}];
}

- (MessageViewModel *)msgViewModel
{
    if (_msgViewModel == nil) {
        _msgViewModel = [[MessageViewModel alloc] init];
    }
    
    return _msgViewModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
